home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
159_01
/
turn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-15
|
17KB
|
933 lines
/* TURN.C no mods for V 1.43
*
* Modified all calls of rand() to irand() for Eco-C88 (BW)
*/
#include "advent.h"
/*
Routine to take 1 turn
*/
VOID PASCAL turn(VOID)
{
auto SHORT i;
/* if closing, then he can't leave except via the main office. */
if (newloc < 9 && newloc != 0 && closing)
{
rspeak(130);
newloc = loc;
if (!panic)
clock2 = 15;
panic = 1;
}
/* see if a dwarf has seen him and has come from where he wants to go. */
if (newloc != loc && !forced(loc) && cond[loc] & NOPIRAT == 0)
{
for (i = 1; i < (DWARFMAX - 1); ++i)
if (odloc[i] == newloc && dseen[i])
{
newloc = loc;
rspeak(2);
break;
}
}
dwarves();
/* on to the regular move. */
if (loc != newloc)
{
++turns;
loc = newloc;
/* check for death */
if (loc == 0)
{
death();
return;
}
/* check for forced move */
if (forced(loc))
{
describe();
domove();
return;
}
/* check for wandering in dark */
if (wzdark && dark() && pct(35))
{
rspeak(23);
oldloc2 = loc;
death();
return;
}
/* describe his situation */
describe();
if (!dark())
{
++visited[loc];
descitem();
}
}
if (closed)
{
if (prop[OYSTER] < 0 && toting(OYSTER))
pspeak(OYSTER, 1);
for (i = 1; i <= MAXOBJ; ++i)
{
if (toting(i) && prop[i] < 0)
prop[i] = -1 - prop[i];
}
}
wzdark = dark();
if (knfloc > 0 && knfloc != loc)
knfloc = 0;
/* run the timer routine */
if (stimer())
return;
/* ask what he wants to do */
/* debug */
if (dbgflg)
printf("Your current location is %d\n", loc);
while (!english())
;
/* act on his instructions */
if (motion)
domove();
else
{
if (object)
doobj();
else
itverb();
}
return;
}
/*
Routine to describe current location
*/
VOID PASCAL describe(VOID)
{
if (toting(BEAR))
rspeak(141);
if (dark())
rspeak(16);
else
{
if (visited[loc] && brief_sw)
descsh(loc);
else
desclg(loc);
}
if (loc == 33 && pct(25) && !closing)
rspeak(8);
return;
}
/*
Routine to describe visible items
*/
VOID PASCAL descitem(VOID)
{
auto SHORT i, state;
for (i = 1; i < MAXOBJ; ++i)
{
if (at(i))
{
if (i == STEPS && toting(NUGGET))
continue;
if (prop[i] < 0)
{
if (closed)
continue;
else
{
prop[i] = 0;
if (i == RUG || i == CHAIN)
++prop[i];
--tally;
}
}
if (i == STEPS && loc == fixed[STEPS])
state = 1;
else
state = prop[i];
pspeak(i, state);
}
}
if (tally == tally2 && tally != 0 && limit > 35)
limit = 35;
return;
}
/*
Routine to handle motion requests
*/
VOID PASCAL domove(VOID)
{
gettrav(loc);
switch (motion)
{
case NULLX:
break;
case BACK:
goback();
break;
case LOOK:
if (detail++ < 3)
rspeak(15);
wzdark = 0;
visited[loc] = 0;
newloc = loc;
loc = 0;
break;
case CAVE:
if (loc < 8)
rspeak(57);
else
rspeak(58);
break;
default:
oldloc2 = oldloc;
oldloc = loc;
dotrav();
loc = 0; /* Modified BW 09/28/85 */
}
return;
}
/*
Routine to handle request to return
from whence we came!
*/
VOID PASCAL goback(VOID)
{
auto SHORT kk, k2, want, temp;
auto TRAV *pSavTrav;
auto SHORT sSavCnt;
if (forced(oldloc))
want = oldloc2;
else
want = oldloc;
oldloc2 = oldloc;
oldloc = loc;
k2 = 0;
if (want == loc)
{
rspeak(91);
return;
}
pSavTrav = pTravel;
sSavCnt = sTravCnt;
for (kk = 0; kk < sTravCnt; ++kk)
{
if (!pTravel[kk].tcond && pTravel[kk].tdest == want)
{
motion = pTravel[kk].tverb;
dotrav();
return;
}
if (!pTravel[kk].tcond)
{
k2 = kk;
temp = pTravel[kk].tdest;
gettrav(temp);
if (forced(temp) && pTravel[0].tdest == want)
k2 = temp;
pTravel = pSavTrav;
sTravCnt = sSavCnt;
}
}
if (k2)
{
motion = pTravel[k2].tverb;
dotrav();
}
else
rspeak(140);
return;
}
/*
Routine to figure out a new location
given current location and a motion.
*/
VOID PASCAL dotrav(VOID)
{
auto SHORT mvflag, hitflag, kk;
auto SHORT rdest, rverb, rcond, robject;
auto SHORT pctt;
newloc = loc;
mvflag = hitflag = 0;
pctt = rand() % 100;
for (kk = 0; kk < sTravCnt && !mvflag; ++kk)
{
rdest = pTravel[kk].tdest;
rverb = pTravel[kk].tverb;
rcond = pTravel[kk].tcond;
robject = rcond % 100;
if (rverb != 1 && rverb != motion && !hitflag)
continue;
++hitflag;
switch (rcond / 100)
{
case 0:
if (rcond == 0 || pctt < rcond)
++mvflag;
/* debug */
if (rcond && dbgflg)
printf("\% move %d %d\n",
pctt, mvflag);
break;
case 1:
if (robject == 0)
++mvflag;
else
{
if (toting(robject))
++mvflag;
}
break;
case 2:
if (toting(robject) || at(robject))
++mvflag;
break;
case 3:
case 4:
case 5:
case 7:
if (prop[robject] != (rcond / 100) - 3)
++mvflag;
break;
default:
bug(37);
}
}
if (!mvflag)
badmove();
else
{
if (rdest > 500)
rspeak(rdest - 500);
else
{
if (rdest > 300)
spcmove(rdest);
else
newloc = rdest;
}
}
return;
}
/*
The player tried a poor move option.
*/
VOID PASCAL badmove(VOID)
{
auto SHORT msg;
msg = 12;
if (motion >= 43 && motion <= 50)
msg = 9;
if (motion == 29 || motion == 30)
msg = 9;
if (motion == 7 || motion == 36 || motion == 37)
msg = 10;
if (motion == 11 || motion == 19)
msg = 11;
if (verb == FIND || verb == INVENTORY)
msg = 59;
if (motion == 62 || motion == 65)
msg = 42;
if (motion == 17)
msg = 80;
rspeak(msg);
return;
}
/*
Routine to handle very special movement.
*/
VOID PASCAL spcmove(SHORT rdest)
{
switch (rdest - 300)
{
case 1: /* plover movement via alcove */
if (!holding || (holding == 1 && toting(EMERALD)))
newloc = (99 + 100) - loc;
else
rspeak(117);
break;
case 2: /* trying to remove plover, bad route */
drop(EMERALD, loc);
break;
case 3: /* troll bridge */
if (prop[TROLL] == 1)
{
pspeak(TROLL, 1);
prop[TROLL] = 0;
move(TROLL2, 0);
move((TROLL2 + MAXOBJ), 0);
move(TROLL, 117);
move((TROLL + MAXOBJ), 122);
juggle(CHASM);
newloc = loc;
}
else
{
newloc = (loc == 117 ? 122 : 117);
if (prop[TROLL] == 0)
++prop[TROLL];
if (!toting(BEAR))
return;
rspeak(162);
prop[CHASM] = 1;
prop[TROLL] = 2;
drop(BEAR, newloc);
fixed[BEAR] = -1;
prop[BEAR] = 3;
if (prop[SPICES] < 0)
++tally2;
oldloc2 = newloc;
death();
}
break;
default:
bug(38);
}
return;
}
/*
Routine to handle player's demise via
waking up the dwarves...
*/
VOID PASCAL dwarfend(VOID)
{
death();
normend(); /* no return from here */
}
/*
normal end of game
*/
VOID PASCAL normend(VOID)
{
score();
exit(1);
}
/*
scoring
*/
VOID PASCAL score(VOID)
{
auto SHORT t, i, k, s;
s = t = 0;
for (i = 50; i <= MAXTRS; ++i)
{
if (i == CHEST)
k = 14;
else
k = i > CHEST ? 16 : 12;
if (prop[i] >= 0)
t += 2;
if (place[i] == 3 && prop[i] == 0)
t += k - 2;
}
printf("%-20s%d\n", "Treasures:", s = t);
t = (MAXDIE - numdie) * 10;
if (t)
printf("%-20s%d\n", "Survival:", t);
s += t;
if (!gaveup)
s += 4;
t = dflag ? 25 : 0;
if (t)
printf("%-20s%d\n"